﻿using System.Globalization;
using System.Windows;
using Central.PumpService;

namespace Central
{
    public partial class UcPump
    {
        public delegate void PumpEvent(int pumpIndex);
        public event PumpEvent Started;
        public event PumpEvent Stopped;

        private readonly PumpDTO _pumpDTO;

        public int Index { get; private set; }

        public double Capacity
        {
            get
            {
                return double.Parse(TextBlockCapacity.Text);
            }
            set
            {
                TextBlockCapacity.Text = value.ToString(CultureInfo.InvariantCulture);
            }
        }

        public bool Running
        {
            get
            {
                return ButtonStop.IsEnabled;
            }
            set
            {
                ButtonStart.IsEnabled = !value;
                ButtonStop.IsEnabled = value;
            }
        }

        public UcPump()
        {
            InitializeComponent();
        }

        public UcPump(int pumpIndex, PumpDTO pumpDTO) : this()
        {
            _pumpDTO = pumpDTO;

            Index = pumpIndex;
            Running = pumpDTO.Running;
            Capacity = pumpDTO.Capacity;
        }

        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            Running = true;
            if (Started != null)
                Started(Index);
        }

        private void btnStop_Click(object sender, RoutedEventArgs e)
        {
            Running = false;
            if (Stopped != null)
                Stopped(Index);
        }
    }
}
